package org.cscarioni

import org.cscarioni.Role

/**
 * User domain class.
 */
class User {

	int daysOfWork
	Set tasks
	int storyPoints
	int storyPointsLeft
	Set estimatedTimes
	String username
	String userRealName
	String passwd
	boolean enabled
	String email
	boolean emailShow
	String description = ''
	String pass = '[secret]'
	Set authorities
	Team team
	UserPreferences preferences
	static hasMany =[tasks:Card,estimatedTimes:EstimatedTimeHistoryForUser,authorities: Role]
	static belongsTo=[Team, Role]
	static transients = [ "daysOfWork" ,"storyPoints","storyPointsLeft","pass"] 
	String toString(){
		username
	}
	public int getStoryPoints(){
		def suma=0
		tasks.each{suma += it.estimatedTime}
		return suma
	}
	public int getStoryPointsLeft(){
		def suma=0
		tasks.each{suma += it.remainingTime}
		return suma
	}

	static constraints = {
		username(blank: false, unique: true)
		userRealName(blank: false)
		passwd(blank: false)
		preferences(nullable:true)
		tasks(nullable:true)
		enabled()
	}
}
